package com.example.basicdemo.controller;


import com.example.basicdemo.model.builder.DeployStartBuilder;
import com.example.basicdemo.model.result.DeployStartResult;
import com.example.basicdemo.service.FlowService;
import com.isyscore.os.dev.util.IsyscoreHashMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;

/**
 * 该控制器集成了以下iSysCore OS的工作流能力
 */
public class FlowController {

    @Autowired
    private FlowService flowService;


    private static IsyscoreHashMap header = new IsyscoreHashMap();

    /**
     * 启动工作流
     */
    @GetMapping("deployStart")
    public void deployStart(@RequestBody DeployStartBuilder builder) {
        //构建参数
//        DeployStartBuilder builder = new DeployStartBuilder()
//                //设置请求头
//                .setHeaders(header);
        //根据request设置请求头
        //.setRequestHeader(request);

        //接口函数调用
        DeployStartResult result = flowService.deployStart(builder);
        //判断结果是否成功
        System.out.println("success: " + result.isSuccess());
        //获取httpCode:http请求结果的code码
        System.out.println("httpCode: " + result.getResponse().getHttpCode());
        //获取httpMessage:http请求结果的消息
        System.out.println("httpMessage: " + result.getResponse().getHttpMessage());
        //获取code:接口返回的错误码
        System.out.println("code: " + result.getResponse().getCode());
        //获取message:接口返回的错误消息
        System.out.println("message: " + result.getResponse().getMessage());
        //获取detail:接口返回的错误附带详情
        System.out.println("detail: " + result.getResponse().getDetail());
        //获取结果数据
        System.out.println("body: " + result.getResponse().getBody());
        //解析结果数据(Json 转 Object)
        System.out.println("parseData: " + result.parseListData());
    }

    /**
     * 消息启动工作流
     */
    @GetMapping("messageStart")
    public void messageStart(@RequestBody DeployStartBuilder builder) {
        //构建参数
//        DeployStartBuilder builder = new DeployStartBuilder()
//                //设置请求头
//                .setHeaders(header);
        //根据request设置请求头
        //.setRequestHeader(request);

        //接口函数调用
        DeployStartResult result = flowService.deployStart(builder);
        //判断结果是否成功
        System.out.println("success: " + result.isSuccess());
        //获取httpCode:http请求结果的code码
        System.out.println("httpCode: " + result.getResponse().getHttpCode());
        //获取httpMessage:http请求结果的消息
        System.out.println("httpMessage: " + result.getResponse().getHttpMessage());
        //获取code:接口返回的错误码
        System.out.println("code: " + result.getResponse().getCode());
        //获取message:接口返回的错误消息
        System.out.println("message: " + result.getResponse().getMessage());
        //获取detail:接口返回的错误附带详情
        System.out.println("detail: " + result.getResponse().getDetail());
        //获取结果数据
        System.out.println("body: " + result.getResponse().getBody());
        //解析结果数据(Json 转 Object)
        System.out.println("parseData: " + result.parseListData());
    }


}
